<template>
    <div class="newSafe">
        <div class="additem tianjia">
            <div class="list">
                <div class="item item1"><i class="iconfont icon-xitong"></i>&nbsp;系统：</div>
                <p>{{getItemName(form.systemId, this.sysList, 'value', 'name')}}</p>
            </div>
            <div class="list" v-if="form.systemId=='S' ||form.systemId==''">
                <div class="item item1"><i class="iconfont icon-quyu"></i>&nbsp;片区：</div>
                <p>{{getItemName(form.areaId, this.selAreaList, 'areaId', 'areaName')}}</p>
            </div>
            <div class="list" v-if="form.systemId!='PROJECT'">
                <div class="item item1"><i class="iconfont icon-icon-"></i>&nbsp;点位：</div>
                <p>{{getItemName(form.siteId, this.siteList, 'siteId', 'siteName')}}</p>
            </div>
            <div class="list" v-if="form.systemId=='PROJECT'">
                <div class="item item1"><i class="iconfont icon-shijian"></i>&nbsp;工程名称：</div>
                <p>{{form.project}}</p>
            </div>
        </div>
        <div>
            <div class="safe-list" v-for="(item,index) in safeList" :key="item.value">
                <div style="flex:0 0 90%">
                    <p class="title"><b>{{item.reactcontent}}</b></p>
                    <p>项目：{{getItemName(item.safeCheckcontent,itemsList, 'value', 'name')}}</p>
                </div>
                <div class="delete" style="flex:0 0 10%">
                    <i class="iconfont icon-shanchu1" @click="dele(index)"></i>
                </div>
            </div>
        </div>
        <button ref="addSafeBtn" type="button" class="btn2 btn-block btn-primary" style="left:0;" @click="goadd()">发现隐患</button>
        <button ref="addSafeBtn" type="button" class="btn2 btn-block btn-primary" style="right:0;" @click="goNext()">提交</button>
    </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import { getItemName } from "@/filters/index.js";

export default {
    data() {
        return {
            itemsList: [],
            selAreaList: [],
            siteList: [],
            sysList: [],
            deptList: [
                { deptId: 15, deptName: '安装分公司' },
                { deptId: 16, deptName: '工程管理部' },
                { deptId: 17, deptName: '思源供水' },
                { deptId: 33, deptName: '广源贸易' },
                { deptId: 37, deptName: '清源污水公司' },
                { deptId: 42, deptName: '净源污水公司' },
                { deptId: 46, deptName: '排水公司' },
            ],
        }
    },
    computed: mapState([
        "form", 'safeList'
    ]),
    mounted() {
        // console.log(this.safeList)
        this.getSys()
        this.getItems()
        if (this.form.systemId == 'P') {
            this.getSitePs()
        }
        if (this.form.systemId == 'S') {
            this.getselSite()
            this.getSelArea()
        }
        if (this.form.systemId == 'W') {
            this.getSiteWs()
        }
    },
    methods: {
        getItemName,
        dele(index) {
            this.$store.dispatch('delItem', index)
        },
        //检查项目
        getItems() {
            this.$api.safe.items().then(res => {
                if (res.success) {
                    this.itemsList = res.data
                }
            });
        },
        //系统列表
        getSys() {
            this.$api.safe.sys().then(res => {
                if (res.success) {
                    this.sysList = res.data
                }
            });
        },
        //部门负责人
        getSelPerson() {
            this.$api.safe.deptpeople().then(res => {
                if (res.success) {
                    this.selPersonList = res.data
                }
            });
        },
        //安全员
        getSafepeople() {
            this.$api.safe.safepeople().then(res => {
                if (res.success) {
                    this.safepeopleList = res.data
                }
            });
        },
        //片区
        getSelArea() {
            this.$api.safe.selArea().then(res => {
                if (res.success) {
                    this.selAreaList = res.data
                }
            });
        },
        //供水点位
        getselSite() {
            this.$api.safe.selSite({
                areaId: this.form.areaId
            }).then(res => {
                if (res.success) {
                    // console.log(res);
                    this.siteList = res.data
                }
            });
        },
        //排水点位
        getSitePs() {
            this.$api.safe.sitePs().then(res => {
                if (res.success) {
                    this.siteList = res.data
                }
            });
        },
        //污水点位
        getSiteWs() {
            this.$api.safe.siteWs().then(res => {
                if (res.success) {
                    this.siteList = res.data
                }
            });
        },

        //路由跳转
        goadd() {
            this.form.safeCheckcontent = ''
            this.form.reactcontent = ''
            this.form.photopath = ''
            this.$router.push({ path: 'yinhuan' })
        },
        goNext() {
            this.$router.push({ path: 'shixian' })
        }
    }
}
</script>

<style>
</style>
